<template>
  <div>
    <el-menu
      :default-active="activeIndex2"
      class="el-menu-demo"
      mode="horizontal"
      @select="handleSelect"
      background-color="#545c64"
      text-color="#fff"
      active-text-color="#ffd04b"
    >
      <el-menu-item index="1" @click="gohome">首页</el-menu-item>

      <el-menu-item index="3" disabled>消息中心</el-menu-item>

      <el-menu-item index="4"
        ><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item
      >
      <el-submenu index="2">
        <template slot="title">{{ uname }}</template>
        <el-menu-item index="2-1" @click="gosign">{{ target }}</el-menu-item>
        <el-menu-item index="2-2" @click="gouserReg">注册</el-menu-item>
        <el-menu-item index="2-3" @click="exituser">退出</el-menu-item>
      </el-submenu>
      <el-menu-item index="5" @click="gocart">购物车</el-menu-item>
    </el-menu>
  </div>
</template>

<script>
import bus from "../bus";
export default {
  data() {
    return {
      activeIndex: "1",
      activeIndex2: "1",
      uname: "个人中心",
      target: "登录",
    };
  },

  mounted() {
    if (sessionStorage.getItem("pwd")) {
      this.uname = sessionStorage.getItem("name");
      this.target = "切换账号";
    }
    bus.$on("sendedit", (res) => {
      this.uname = res;
      this.target = "切换账号";
    });
  },
  methods: {
    handleSelect(key, keyPath) {
      // console.log(key, keyPath);
    },
    gohome() {
      this.$router.push({
        path: "/home",
      });
    },
    gouserReg() {
      this.$router.push({
        path: "/userReg",
      });
    },
    gosign() {
      this.$router.push({
        path: "/sign",
      });
    },
    //去购物车
    gocart() {
      this.$router.push({
        path: "/cart",
      });
    },
    //退出账号
    exituser() {
      const confirm = window.confirm("你确定要退出当前用户吗?");
      if (confirm) {
        sessionStorage.removeItem("pwd");
        sessionStorage.removeItem("name");
        // sessionStorage.setItem("target", "登录");
        this.uname = "个人中心";
        this.target = "登录";
      } else {
      }
    },
  },
};
</script>

<style lang="scss" scoped>
</style>